const deepClone = require("../template.js")

/** 2. 嵌套结构测试 */
function testNested() {
  console.log(
    "2.1 嵌套对象:",
    (() => {
      const obj = {
        a: 1,
        b: {
          c: 2,
          d: {
            e: 3,
            f: "nested"
          }
        }
      }
      const cloned = deepClone(obj)
      obj.b.d.e = 999 // 修改原对象
      return cloned.b.d.e === 3 && cloned !== obj && cloned.b !== obj.b
    })()
  )

  console.log(
    "2.2 嵌套数组:",
    (() => {
      const arr = [1, [2, [3, 4]], { a: 5 }]
      const cloned = deepClone(arr)
      arr[1][1][0] = 999 // 修改原数组
      return cloned[1][1][0] === 3 && cloned !== arr && cloned[1] !== arr[1]
    })()
  )

  console.log(
    "2.3 对象与数组混合:",
    (() => {
      const mixed = {
        arr: [1, 2, { nested: [3, 4] }],
        obj: {
          inner: [5, 6, { deep: 7 }]
        }
      }
      const cloned = deepClone(mixed)
      mixed.arr[2].nested[0] = 999
      return cloned.arr[2].nested[0] === 3 && cloned.arr !== mixed.arr
    })()
  )

  console.log(
    "2.4 深度嵌套验证:",
    (() => {
      const deep = {
        level1: { level2: { level3: { level4: { value: "deep" } } } }
      }
      const cloned = deepClone(deep)
      deep.level1.level2.level3.level4.value = "changed"
      return (
        cloned.level1.level2.level3.level4.value === "deep" &&
        cloned.level1 !== deep.level1
      )
    })()
  )

  console.log("--------------------")
}

testNested()

module.exports = testNested
